home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / ib.772 < prev    next >
Text File  |  1992-02-06  |  2KB  |  54 lines

  1. {\rtf0\ansi{\fonttbl\f1\fnil Times-Roman;\f3\fmodern Ohlfs;\f4\fmodern Courier;\f0\fswiss Helvetica;}
  2. \paperw13040
  3. \paperh10800
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f1\b0\i0\ul0\fs28 interface builder outlets\
  8. \
  9. Q:  I've made connections in InterfaceBuilder like I have a zillion times before.  So, why are all of my outlets nil when I run my program?\
  10. \
  11. A: 
  12. \fc0 In earlier releases, you had to provide a method to set each outlet that you declared in a new class.  For example, if your subclass had an outlet named 
  13. \b myOutlet
  14. \b0 , the source code for your subclass had to declare and implement this method:\
  15. \
  16.  
  17. \f3\fs22     - setMyOutlet:anObject\
  18.     \{\
  19.         myOutlet = anObject;\
  20.          return self;\
  21.     \}\
  22.     \
  23.  
  24. \f1\fs28 In InterfaceBuilder, the Unparse item in the Class's window would create these "set" methods automatically.  \
  25. \
  26. These outlet initialization methods are no longer required.  However, for backward compatibility, if an object responds to such a message, the runtime system will use them to initialize outlets.  Basically, the runtime system does this:\
  27.  
  28. \f4\fs24     \
  29.  
  30. \f3\fs22     if ([yourObject respondsTo:@selector(setMyOutlet:)])\
  31.         setMyOutlet:anObject\
  32.  
  33. \f1\fs28 \
  34. All is hunky dory, if you remember the days when these methods were required.  Now that InterfaceBuilder does not generate them automatically, it is not obvious that these method names have special meaning.  So, if you have a method name 
  35. \b setMyOutlet 
  36. \b0 you must set the outlet within that method.  If you don't initialize the outlet, then 
  37. \b myOutlet
  38. \b0  will be nil at runtime.\
  39. \
  40. Overall it is best to avoid 
  41. \b setMyOutlet
  42. \b0  style method names altogether, unless you are consciously taking advantage of this "feature," and are doing
  43. \pard\tx1800\tx2160\tx2520\fc0  additional initialization within the "set" method.
  44. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0   Care must be taken, as the order in which outlets and other objects are  initialized is neither guaranteed nor predictable.
  45. \pard\tx1800\tx2160\tx2520\fc0 \
  46.  
  47. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 \
  48. QA772\
  49. \
  50. Valid for 1.0\
  51. Valid for 2.0\
  52. \
  53.  
  54.